/**
 * 
 * @author Paul Peasegood
 * Stores player stat e.g. HP, energy etc.
 *
 */
public class StatCounter {
	
	protected final int max;
	protected int current;
	protected final double regenerate;
	protected int remain; //used to hold the remainder of the regenate function
	
	/**
	 * create new stat set to maxim with 0 regeneration 
	 * @param max - maxim value
	 */
	public StatCounter (int max)
	{
		this.max = max;
		this.current = max;
		this.regenerate = 0;
	}
	/**
	 * create new stat set to maxim value with regeneration
	 * @param max - maxim value
	 * @param regenerate - regeneration per round
	 */
	public StatCounter (int max, double regenerate)
	{
		this.max = max;
		this.current = max;
		this.regenerate = regenerate;
	}
	
	/**
	 * gets the maxim value
	 * @return
	 */
	public int getMax()
	{
		return this.max;
	}
	/**
	 * gets the current value
	 * @return
	 */
	public int getCurrent()
	{
		return this.current;
	}
	/**
	 * sets current total
	 * @param x - number  total to be set to
	 */
	public void setCurrent(int x)
	{
		this.current = x;
	}
	
	/**
	 * current total is decrease
	 * @param x - amount to decrease by
	 */
	public void decrease(int x)
	{
		this.current = this.current - x;
	}
	/**
	 * current total is increase
	 * @param x - amount to restore by
	 */
	
	public void increase(int x)
	{
		this.current = this.current + x;
		if(this.current > this.max)
		{
			this.current = this.max;
		}
	}
	/**
	 * used each turn to regenerate a set amount
	 */
	public void regenerate()
	{
		int x = (int) ((this.regenerate * 100) / 100);
		this.remain = this.remain + (int) ((this.regenerate * 100) % 100);
		if (this.remain >= 100)
		{
			this.remain = this.remain - 100;
			x++;
		}
		this.current = this.current + x;
		if (this.current > this.max)
		{
			this.current = this.max;
		}
		
	}
	/**
	 * current total is set to max
	 * @param x
	 */
	public void fullRestore()
	{
		this.current = this.max;
	}
	
	
	public String toString()
	{
		return this.current + "/" + this.max 
				+ " (" +this.regenerate+ ")";
	}
	
}
